<script language="javascript">
	function viewproductByCat(CatID){
		window.location='?mod=product&catid=' + CatID;
	}
	function viewProductByLocation(LID){
		window.location='?mod=product&location=' + LID;
	}
	function viewProductByStatus(SID){
		window.location='?mod=product.listcat&act=' + SID;
	}
	function viewProductByHOT(HID){
		window.location='?mod=product&hot=' + HID;
	}
</script>
<?
if(isset($_GET['method']))
{
	$method = $_GET['method'];
	if($method=="del"){
		$sListId="";
		if(isset($_POST["chon"]))$sListId=$_POST["chon"];
		$sql="delete from ".$prefix."loaisanpham where c_id in('".str_replace(",","','",$sListId)."')";
		mysql_query($sql);
		Redirect("Bạn đã xoá thành công","?mod=product.listcat");
	}
	else if($method=="move"){
		$IdList=$_GET["id"];
		$move=$_GET["move"];
		$sql = "UPDATE ".$prefix."loaisanpham
					SET c_thutu = c_thutu+$move
					WHERE c_id = $IdList";
		mysql_query($sql);
		Redirect("","?mod=product.listcat");
	}else if($method=="act"){
		$IdList=$_GET["id"];
		$act=$_GET["act"];
		if($act==1) $iact=0;else $iact=1;
		$sql="update ".$prefix."loaisanpham set c_hienthi=$iact where c_id=$IdList";
		mysql_query($sql);
		Redirect("","?mod=product.listcat");		
	}else if($method=="delete"){
		$IdList=$_GET["id"];
		$sql="delete from ".$prefix."loaisanpham where c_id=$IdList";
		mysql_query($sql);
		Redirect("Đã xóa thành công","?mod=product.listcat");		
	}
}
$where = "";
if(isset($_GET['catid']))
{
	$catid = $_GET['catid'];
	$where .=" where t_loaisanpham=$catid";
}
else if(isset($_GET['location'])){
	$location = $_GET['location'];
	$where .=" where t_tinhthanh=$location";
}else if(isset($_GET['act'])){
	$act = $_GET['act'];
	$where .= " where c_hienthi=$act";
}else if(isset($_GET['hot'])){
	$hot = $_GET['hot'];
	$where .= " where t_noibat=$hot";
}else{
	$where = $where;
}
	///////Paging
	$strSQL = "select * from ".$prefix."loaisanpham".$where." order by c_thutu ASC";
	$pp=10; 
	$parr=array();
	$parr=paging($strSQL,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$strSQL.=" LIMIT $limitvalue, $pp";
	$rs = mysql_query($strSQL) or die('Not query');
	$i=0;
	$tree = "";                    // Clear the directory tree
	$depth = 1;                    // Child level depth.
	$top_level_on = 1;            // What top-level category are we on?
	$exclude = array();            // Define the exclusion array
	array_push($exclude, 0);    // Put a starting value in it 	
	$isexits=false;
	
	if(mysql_num_rows($rs)) $isexits=true;
?>
<div class="newsList-path"></div>
	<div style="margin-bottom:5px; font-size:14px;">
	<?
	$sql = "select count(*) as total from ".$prefix."loaisanpham".$where."";
	$result = mysql_query($sql) or die("Can't connect database");
	$row = mysql_fetch_array($result);
	?>
	 Có <?=$row['total']?> loại sản phẩm được tìm thấy <div align="left" class="newsList-search-up">
	 <br />
	<a href="?mod=product.listcat.add"><img src="images/add.png" border="0" alt="Thêm mới"/></a>&nbsp;<a href="?mod=product.listcat"><img src="images/list.png" border="0" alt="Danh sách"/></a>
	</div></div>
	<div align="right" class="newsList-search-up">
	<strong>Lọc loại sản phẩm</strong>&nbsp;
	  &nbsp;<select name="FilterByStatus" id="SID" onchange="return(viewProductByStatus(this.value));">
	<option value="">----Tất cả----</option>
	<option value="1">Đã kích hoạt</option>
	<option value="0">Chưa kích hoạt</option>
	  </select>
	</div>
	<form name="frmListSp" method="post" action="?mod=product.listcat&method=del" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
	<input type="hidden" name="chon" />
	<table width="100%" border="1" bordercolor="#B2DAEE" cellpadding="4">
		<tr class="newsList-content-head">
		<td width="4%" class="newsList-content-view"><input type="checkbox" name="chkall" value="0" <? if($isexits) echo "onClick=\"docheck(this.form,0);\""?>></td>
			<td width="33%" class="newsList-content-title">Tên loại sản phẩm</td>

		  <td width="32%" class="newsList-content-view"><div align="center">Danh mục cha </div></td>
			<td width="11%" class="newsList-content-view"><div align="center">Hiển thị </div></td>
			<td width="11%" class="newsList-content-view"><div align="center">Thứ tự </div></td>
			<td width="9%" class="newsList-content-view"><div align="center">Tùy chọn </div></td>
		</tr>
				<?
				while($rows = mysql_fetch_array($rs))
				{
					$i++;
					$c_id = $rows['c_id'];
					$c_ten = $rows['c_ten'];
					$c_id_cha = $rows['c_id_cha'];
					$c_hienthi = $rows['c_hienthi'];
				?>				
		<tr onmouseover="this.bgColor='#FEF2CB';" onmouseout="this.bgColor='#FFFFFF';" class="newsList-content-list" <? if($i%2==0) echo "bgcolor='#f2fff2'";?>>
			<td class="newsList-content-title"><input type="checkbox" name="Xoa" value="<?=$c_id?>" onClick="docheckone(this.form);"></td>
			<td class="newsList-content-title">
            	<table cellpadding="0" cellspacing="0" width="100%">
                <tr>
					<td>
						<a class="newsList-link newsList-name" href="">
						<b><?=$c_ten?></b></a>					</td>
                 </table>			</td>
			<td class="newsList-content-view"><div align="center">
			<?=getLoaiSanPham($c_id_cha);?>
			  </div></td>
			<td class="newsList-content-view"><div align="center"><a href="?mod=product.listcat&method=act&act=<?=$c_hienthi;?>&id=<?=$c_id?>"><?=ImgActive($c_hienthi);?></a></div></td>
			<td class="newsList-content-view"><div align="center"> <a href="?mod=product.listcat&amp;method=move&amp;move=1&amp;id=<?=$c_id?>" class="menu"><img src="images/down.gif" border="0" /></a> <a href="?mod=product.listcat&amp;method=move&amp;move=-1&amp;id=<?=$c_id?>" class="menu"><img src="images/up.gif" border="0" /></a> </div></td>
		  <td class="newsList-content-view"><div align="center"><a href="?mod=product.listcat.add&amp;pid=<?=$c_id?>" class="menu"><img src="images/new.gif" border="0" /></a><a href="?mod=product.listcat.add&amp;method=edit&amp;pid=<?=$c_id_cha?>&amp;id=<?=$c_id?>" class="menu"><img src="images/edit.gif" border="0" /></a> <a href="?mod=product.listcat&amp;method=delete&amp;id=<?=$c_id?>" class="menu" onclick="return confirm('Bạn có chắc chắn muốn xóa không?')"><img src="images/delete_on.gif" border="0" /></a></div></td>
        </tr>
		<? }?>
	<tr>
   <td colspan="10" align="center">
   <input type="submit" name="submit" value="   Xoá   " class="Button">
   <input type="reset" value="Làm lại" class="Button">   </td>
   </tr>
</table>
	</form>
	<div class="newsList-pagging">
	<div class="raovat-paging-bound">
	<span style="padding:5px;">
	<p align="center" class="font">
			<?php echo page_div( "?mod=product.listcat&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	</span>
	</div>
	</div>
	<div class="newsList-button-back"><a href="javascript: history.back()">[Quay lại]</a></div>